<!DOCTYPE html>
<html>
<head>
    <include file="Include:meta"/>
    <title>添加联系人-目的地运营集团数据管理平台</title>
    <include file="Include:style"/>
    <style>
        .w50 {
            width: 50px;
        }
    </style>
</head>
<body>
<if condition="$project_id eq NULL">
<include file="Include:header" />
<include file="Include:left" />
</if>
<div id="main">
    <div class="crumbs">
        <if condition="$project_id eq NULL"><div class="crumbs-text">联系人管理 > 添加联系人</div></if>
    </div>
    <div id="content">
        <form action="__APP__/Crm/contact_add" method="post" id="contact_add_form">
			<input name="project_id", value="{$project_id}" type="hidden">
            <div class="form-main">
                <div class="form-title">添加联系人</div>
                <div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>名称</div>
					<div class="input-item" style="position:relative;">
						<input type="text" name="username" class="form-control required-text w200" autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
                    <div class="input-label">关联项目</div>
                    <div class="input-item">
                        <select name="contact_project[]" id="contact_project" multiple='multiple' class="form-control w400"
                                autocomplete="off">
                            <foreach name="res_project" item="vo">
                                <option value="{$vo['project_id']}">{$vo['name']}</option>
                            </foreach>
                        </select>
                    </div>
                </div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>公司名称</div>
					<div class="input-item">
						<input type="text" name="company_name" class="form-control required-text w500" autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<!-- <div class="form-item"> -->
					<!-- <div class="input-label"><span class="asterisk">*</span>主要联系人</div> -->
					<!-- <div class="input-item"> -->
						<!-- <span class="checkbox-item"> -->
							<!-- <label class="radio-inline"><input type="radio" name="is_main" value="1">是</label> -->
							<!-- <label class="radio-inline"><input type="radio" name="is_main" value="2">否</label> -->
							<!-- <span class="error-item">必填项</span> -->
						<!-- </span> -->
						
					<!-- </div> -->
				<!-- </div> -->
				<div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>性别</div>
                    <div class="input-item">
                        <select name="gender" class="form-control w100 required_select" autocomplete="off">
							<option value="0">请选择</option>
                            <option value="1">男</option>
                            <option value="2">女</option>
                        </select>
						<span class="error-item">必填项</span>
                    </div>
                </div>
				<div class="form-item clearfix">
					<div class="item-float" style="width:20%">
						<div class="input-label"><span class="asterisk">*</span>手机号</div>
						<div class="input-item">
							<input type="text" name="mobilephone" class="form-control required-text w200" autocomplete="off">
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="item-float" style="width:20%">
						<div class="input-label">座机号</div>
						<div class="input-item">
							<input type="text" name="telephone" class="form-control w200" autocomplete="off">
							<span class="error-item"></span>
						</div>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">职位</div>
					<div class="input-item">
						<input type="text" name="job" class="form-control w200" autocomplete="off">
						<select name="job_level" class="form-control w100" autocomplete="off">
							<foreach name="typelist.job_level" item="vo">
                                <option value="{$vo['id']}">{$vo['name']}</option>
                            </foreach>
                        </select>
					</div>
				</div>
				<div class="form-item">
                    <div class="input-label">决策关系</div>
                    <div class="input-item">
                        <select name="decision_relation" class="form-control w100" autocomplete="off">
							<foreach name="typelist.relation" item="vo">
                                <option value="{$vo['id']}">{$vo['name']}</option>
                            </foreach>
                        </select>
                    </div>
                </div>
				<div class="form-item">
                    <div class="input-label">地址</div>
                    <div class="input-item">
                        <select name="province_id" class="form-control w100" autocomplete="off">
							<option value='-10'>省</option>
							<foreach name="typelist.province_list" item="vo">
                                <option value="{$vo['id']}">{$vo['name']}</option>
                            </foreach>
                        </select>
						<select name="city_id" class="form-control w100" autocomplete="off">
							<option value='-10'>市</option>
                        </select>
						<input type="text" name="address" class="form-control w380" placeholder="详细地址（可不填）" autocomplete="off">
						<span class="error-item"></span>
                    </div>
                </div>
				<div class="form-item clearfix">
					<div class="item-float" style="width:20%">
						<div class="input-label">生日</div>
						<div class="input-item">
							<input type="text" name="birthday" class="form-control w200" autocomplete="off">
						</div>
					</div>
					<div class="item-float" style="width:20%">
						<div class="input-label">爱好</div>
						<div class="input-item">
							<input type="text" name="hobby" class="form-control w200" autocomplete="off">
						</div>
					</div>
				</div>
				<div class="form-item clearfix">
					<div class="item-float" style="width:20%">
						<div class="input-label">微信</div>
						<div class="input-item">
							<input type="text" name="wx" class="form-control w200" autocomplete="off">
						</div>
					</div>
					<div class="item-float" style="width:20%">
						<div class="input-label">QQ</div>
						<div class="input-item">
							<input type="text" name="qq" class="form-control w200" autocomplete="off">
							<span class="error-item"></span>
						</div>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">邮箱</div>
					<div class="input-item">
						<input type="text" name="email" class="form-control w500" autocomplete="off">
						<span class="error-item"></span>
					</div>
				</div>
				<div class="form-item clearfix">
					<div class="item-float" colspan="2">
						<div class="input-label">备注</div>
						<div class="input-item">
							<textarea name="remark" class="form-control w500 h150" autocomplete="off"></textarea>
						</div>
					</div>
				</div>
            </div>
            <p class="red Text_c bili_item hide"></p>
            <div class="form-btn-item"><input type="submit" value="提交" class="btn btn-submit">
                <button class="btn btn-default goback" type="button">返回</button>
            </div>
        </form>
    </div>
</div>
</body>
<include file="Include:javascript"/>
<script type="text/javascript">
    $(function () {
		/*省市联动*/
		$("[name='province_id']").change(function(){
			var id = $(this).val();
			$.ajax({
				type:"POST",
				dataType:'json',
				data:{'region':id,'type':1,'bool':1},
				url:"__APP__/Communal/get_province_city",
				success:function(data){
					var option = "";
					if(data){
						option += "<option value='-10'>请选择</option>";
						if(data){
							for(var i=0;i<data.length;i++){
								option += "<option value="+data[i].id+">"+data[i].name+"</option>";
							}
						}
					}else{
						option += "<option value='-10'>市</option>";
					}
					$("[name='city_id']").html(option).select2();
				}
			});
		});
        /*表单验证*/
        $(".btn-submit").click(function () {
            var tag = false;
			//必填判断
            $('.required-text').each(function () {
                var val = $(this).val();
                if (val == '') {
                    $(this).next('.error-item').show();
                    tag = true;
                }
            })
			//必选判断
            $('.required_select').each(function () {
                var val = $(this).val();
                if (val == 0) {
                    $(this).siblings('.error-item').show();
                    tag = true;
                }
            })
			//单选必选判断
			<!-- $(".checkbox-item").each(function(){ -->
				<!-- var $val = $("[name='is_main']:checked").length; -->
				<!-- if($val==0){ -->
					<!-- $(".checkbox-item").find(".error-item").show(); -->
					<!-- tag = true; -->
				<!-- } -->
			<!-- }); -->
			$("[name='mobilephone']").each(function(){
				var $val = $(this).val();
				if($val!="" && !/^1[3|4|5|7|8]\d{9}$/.test($val)){
					$(this).next(".error-item").html("输入正确的手机格式").show();
					tag = true;
				}
			});
			$("[name='telephone']").each(function(){
				var $val = $(this).val();
				if($val!="" && !/^(\d{3,4}\-?)?\d{7,8}(\-\d{3,4})?$/.test($val)){
					$(this).next(".error-item").html("输入正确的座机格式").show();
					tag = true;
				}
			});
			$("[name='email']").each(function(){
				var $val = $(this).val();
				if($val!="" && !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($val)){
					$(this).next(".error-item").html("输入正确的email格式").show();
					tag = true;
				}
			});
			$("[name='qq']").each(function(){
				var $val = $(this).val();
				if($val!="" && !/^[1-9]\d{4,10}$/.test($val)){
					$(this).next(".error-item").html("输入正确的qq格式").show();
					tag = true;
				}
			});
			var mobile = $("[name='mobilephone']").val();
			if(mobile!=""){
				$.ajax({
					type:"POST",
					async:false,
					dataType:"json",
					data:{"phone":mobile,"type":1},
					url:"__APP__/Communal/checkPhoneNumber",
					success:function(data){
						if(data.status==0){
							$("[name='mobilephone']").next(".error-item").html(data.msg).show();
							tag = true;
						}else{
							tag = false;
						}
					}
				});
			}
			var phone = $("[name='telephone']").val();
			if(phone!=""){
				$.ajax({
					type:"POST",
					async:false,
					dataType:"json",
					data:{"phone":mobile,"type":2},
					url:"__APP__/Communal/checkPhoneNumber",
					success:function(data){
						if(data.status==0){
							$("[name='telephone']").next(".error-item").html(data.msg).show();
							return false;
						}
					}
				});
			}
            if (tag) {
                return false;
            }
        });

        /*取消错误提示*/
        $('.required_select').change(function () {
            $(this).siblings('.error-item').hide();
        });
        $(".required-text").focus(function () {
            $(this).nextAll('.error-item').hide();
        });
		<!-- $(".checkbox-item").on('click',"label",function(){ -->
			<!-- $(this).parents(".checkbox-item").find(".error-item").hide(); -->
		<!-- }); -->
    });
</script>
</html>